/**
 * MeetSummaryDaoImpl.java
 */
package com.prs.crm.dao.meeting.impl;

import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.meeting.MeetSummaryDao;
import com.prs.crm.domain.flow.WorkFlowInstance;
import com.prs.crm.domain.hr.Resume;
import com.prs.crm.domain.meeting.MeetStart;
import com.prs.crm.domain.meeting.MeetSummary;

/**
 * @author ZhuDongMei
 * @E-mail:1223984339@qq.com
 * @qq:1223984339
 * @version 创建时间：2011-3-16 上午11:12:28 简单说明
 */

public class MeetSummaryDaoImpl extends BaseDaoImpl<MeetSummary> implements
		MeetSummaryDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<MeetSummary> getAllMeetSummary() {
		// TODO Auto-generated method stub
		return (List<MeetSummary>)this.getHibernateTemplate().execute(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session session)
			throws HibernateException, SQLException {
		// TODO Auto-generated method stub
		Criteria criteria = session.createCriteria(MeetSummary.class);
		criteria.addOrder(Order.asc("id"));
		return criteria.list();
	}

		});
	}

	/* (non-Javadoc)
	 * @see com.prs.crm.dao.meeting.MeetSummaryDao#getMeetSummaryByMeetStart(com.prs.crm.domain.meeting.MeetStart)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public MeetSummary getMeetSummaryById(final MeetStart meetStart) {
		return (MeetSummary)getHibernateTemplate().execute(   
			      new HibernateCallback() {   
					@SuppressWarnings("unchecked")
					public Object doInHibernate(Session session) throws HibernateException {   
			        	Criteria criteria =  session.createCriteria(MeetSummary.class);
			        	criteria.add(Restrictions.eq("meetStart", meetStart));
			        	List<MeetSummary> result = criteria.list();
			        	if  (result.size()>0)
			        		return result.get(0);
			        	else
			        		return null;
			        }   
			      }   
			    ); 
}

	@Override
	public MeetSummary getMeetSummaryById(Integer id) {
		Criteria criteria = this.getSession().createCriteria(MeetSummary.class)
		.add(Restrictions.eq("id", id));
		List<MeetSummary> list = criteria.list();
		if(list.size() == 0){
			return null;
		}
		return list.get(0);
	}
}
